package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/order")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> selectStatistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.selectStatistics();
        return Result.success(orderStatisticsVO);
    }

    @GetMapping("/conditionSearch")
    public Result<PageResult> selectConditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = orderService.selectConditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/details/{id}")
    public Result<?> selectDetails(@PathVariable Long id) {
        OrderVO orders = orderService.selectDetails(id);
        return Result.success(orders);
    }

    @PutMapping("/delivery/{id}")
    public Result<?> updateDelivery(@PathVariable Long id) {
        orderService.updateDelivery(id);
        return Result.success();
    }

    @PutMapping("/confirm")
    public Result<?> confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }

    @PutMapping("/rejection")
    public Result<?> rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    public Result<?> completeOrder(@PathVariable Long id) {
        orderService.completeOrder(id);
        return Result.success();
    }

    @PutMapping("/cancel")
    public Result<?> cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }
}
